<?php

class Admin_Form_Content extends Twitter_Bootstrap_Form_Horizontal
{
    public function getFormId()
    {
        $className = get_class($this);
        return strtolower($className);
    }

    public function init()
    {
        $this->setIsArray(true);
        //$this->setElementsBelongTo('bootstrap');

        $this->_addClassNames('form-horizontal');

        // Category name
        $this->addElement('text', 'name', array(
            'id' => $this->getFormId() . '_name',
            'label' => $this->getView()->translate('NAME'),
            'maxlength' => 45,
            'class' => 'input-xlarge'
        ));
        $this->getElement('name')
                ->addFilter('StringTrim')
                ->addFilter('StripTags')
                ->setRequired(true)
                ->addValidators(array(
                    array('NotEmpty', true),
                    array('stringLength', false, array(3, 45)),
                ));

        // Published
        $this->addElement('radio', 'published', array(
            'id' => $this->getFormId() . '_published',
            'label' => $this->getView()->translate('PUBLISHED'),
            'multiOptions' => array('yes' => $this->getView()->translate('YES_'), 'no' => $this->getView()->translate('NO_')),
            'value' => 'yes'
        ));
        $this->getElement('published')
                ->addFilter('StringTrim')
                ->addFilter('StripTags')
                ->setRequired(true)
                ->addValidators(array(
                    array('NotEmpty', true)
                ));

        // Introtext
        $this->addElement('wysiwyg', 'introtext', array(
            'id' => $this->getFormId() . '_introtext',
            'label' => $this->getView()->translate('INTROTEXT'),
            'editorToolbar' => 'basic',
            'editorHeight' => '120'
        ));
        $this->getElement('introtext')
                ->addFilter('StringTrim')
                ->setRequired(true)
                ->addValidators(array(
                    array('NotEmpty', true)
                ));

        // Fulltext
        $this->addElement('wysiwyg', 'fulltext', array(
            'id' => $this->getFormId() . '_fulltext',
            'label' => $this->getView()->translate('FULLTEXT'),
            'editorHeight' => '350'
        ));
        $this->getElement('fulltext')
                ->addFilter('StringTrim')
                ->setRequired(true)
                ->addValidators(array(
                    array('NotEmpty', true)
                ));

        // Images
        $config = Zend_Registry::get('configuration');
        $this->addElement('file', 'file', array(
            'id' => $this->getFormId() . '_file',
            'label' => $this->getView()->translate('IMAGE')
        ));
        $this->getElement('file')
                ->setDestination($config->upload->path . DS . 'images')
                ->addValidators(array(
                    array('Count', false, 1),
                    array('Size', false, $config->upload->image->maxsize),
                    array('Extension', false, explode(',', $config->upload->image->extension)),
                    //array('MimeType', false, explode(',', $config->upload->image->mimetype))
                ));

        // Images preview
        $this->addElement('render', 'images', array(
            'id' => $this->getFormId() . '_images',
            'viewPath' => 'form/element-image-preview.phtml'
        ));

        // Id
        $this->addElement('hidden', 'id', array(
            'id' => $this->getFormId().'_id'
        ));
        $this->getElement('id')->removeDecorator('Wrapper')->removeDecorator('HtmlTag');

        // Category
        $this->addElement('select', 'category_id', array(
            'id' => $this->getFormId().'_category_id',
            'label' => $this->getView()->translate('CATEGORY'),
            'required' => true
        ));
        $this->getElement('category_id')
                ->setRegisterInArrayValidator(false)
                ->addValidators(array(
                    array('NotEmpty', true),
                    array('Int')
                ));

        // Section Id
        $this->addElement('hidden', 'section_id', array(
            'id' => $this->getFormId().'_section_id',
            'required' => true
        ));
        $this->getElement('section_id')
                ->setRequired(true)
                ->addValidators(array(
                    array('NotEmpty', true),
                    array('Int')
                ));
        $this->getElement('section_id')->removeDecorator('Wrapper')->removeDecorator('HtmlTag');
    }

}